package com.itrus.cvm;

import com.itrus.cert.Names;
import com.itrus.cert.X509CRL;
import com.itrus.cert.X509Certificate;
import com.itrus.util.Semaphore;
import java.io.IOException;
import java.security.NoSuchProviderException;
import java.security.cert.CertificateException;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CRLContext
{
  private static Log log = LogFactory.getLog("ITRUS-CVM");
  private String m_AccountHash = null;
  private String m_CAFilePath = null;
  private String m_CaAlias;
  private X509Certificate m_CaCert = null;
  private String m_CrlFilePath = null;
  private String m_CrlUrl = null;
  private int[] m_RetryPolicy = null;
  private boolean m_TimingDownload = false;
  private String m_UserCrlUrl = null;
  private X509CRL m_X509CRL = null;
  private boolean m_isNotCheckCRL = false;
  private Semaphore m_semaphore = new Semaphore();
  private int m_status = 0;

  public CRLContext(CRLContextConfInfo paramCRLContextConfInfo)
    throws IOException, CertificateException, NoSuchProviderException
  {
    this.m_CaCert = X509Certificate.getInstanceFromFile(paramCRLContextConfInfo.getCAFilePath());
    this.m_CAFilePath = paramCRLContextConfInfo.getCAFilePath();
    this.m_CrlFilePath = paramCRLContextConfInfo.getCRLFilePath();
    this.m_CrlUrl = paramCRLContextConfInfo.getCRLUrl();
    this.m_RetryPolicy = paramCRLContextConfInfo.getRetryPolicy();
    Names localNames = this.m_CaCert.getSubjectNames();
    String str;
    if (localNames.getItem("CN") != null)
      str = localNames.getItem("CN");
    while (true)
    {
      this.m_CaAlias = str;
      this.m_isNotCheckCRL = paramCRLContextConfInfo.isNotCheckCRL();
      this.m_AccountHash = paramCRLContextConfInfo.getAccountHash();
      this.m_TimingDownload = paramCRLContextConfInfo.isTimingDownload();
      try
      {
        this.m_X509CRL = X509CRL.getInstanceFromFile(this.m_CrlFilePath);
        if ((!this.m_isNotCheckCRL) && (!isCRLIssuedByLegalCA(this.m_X509CRL, this.m_CaCert)))
        {
          log.warn("(" + this.m_CaAlias + ")下载到的CRL不是由指定CA颁发的。");
          this.m_X509CRL = null;
        }
        log.info("加载CRL成功(" + this.m_CaAlias + "),(CrlFilePath:" + this.m_CrlFilePath + ")。");
        getX509CRL();
        return;
        str = (String)localNames.getItems((String)localNames.keys().nextElement()).elementAt(0);
      }
      catch (Exception localException)
      {
        while (true)
          log.warn("(" + this.m_CaAlias + ")读取CRL文件错误：[" + localException.getMessage() + "]" + this.m_CrlFilePath);
      }
    }
  }

  public void cancelTimingDownload()
  {
    this.m_TimingDownload = false;
  }

  public String getAccountHash()
  {
    return this.m_AccountHash;
  }

  public String getCAFilePath()
  {
    return this.m_CAFilePath;
  }

  public String getCaAlias()
  {
    return this.m_CaAlias;
  }

  public X509Certificate getCaCert()
  {
    return this.m_CaCert;
  }

  public String getCrlFilePath()
  {
    return this.m_CrlFilePath;
  }

  public String getCrlUrl()
  {
    return this.m_CrlUrl;
  }

  public int[] getRetryPolicy()
  {
    return this.m_RetryPolicy;
  }

  public int getStatus()
  {
    return this.m_status;
  }

  public String getUserCrlUrl()
  {
    return this.m_UserCrlUrl;
  }

  public X509CRL getX509CRL()
  {
    try
    {
      this.m_semaphore.waitReadSemaphore();
      if ((this.m_X509CRL == null) || (this.m_TimingDownload))
      {
        if ((this.m_CrlUrl == null) && (this.m_UserCrlUrl == null))
          log.error("(" + this.m_CaAlias + ")" + "无法从配置文件或用户证书中取得CRL下载地址。");
      }
      else
        return this.m_X509CRL;
      if (this.m_status != 0);
    }
    catch (InterruptedException localInterruptedException)
    {
    }
    finally
    {
      this.m_semaphore.releaseReadSemaphore();
    }
  }

  public X509CRL getX509CRL(String paramString)
  {
    this.m_UserCrlUrl = paramString;
    return getX509CRL();
  }

  public boolean isCRLIssuedByLegalCA(X509CRL paramX509CRL, X509Certificate paramX509Certificate)
  {
    try
    {
      paramX509CRL.verify(paramX509Certificate.getPublicKey());
      return true;
    }
    catch (Exception localException)
    {
      log.debug(localException.getMessage());
    }
    return false;
  }

  public boolean isNotCheckCRL()
  {
    return this.m_isNotCheckCRL;
  }

  public boolean isTimingDownload()
  {
    return this.m_TimingDownload;
  }

  public void setCrlUrl(String paramString)
  {
    this.m_CrlUrl = paramString;
  }

  public void setDownloaded()
  {
    this.m_status = 0;
  }

  public void setDownloading()
  {
    this.m_status = 1;
  }

  // ERROR //
  public void setX509CRL(X509CRL paramX509CRL)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 73	com/itrus/cvm/CRLContext:m_semaphore	Lcom/itrus/util/Semaphore;
    //   4: invokevirtual 252	com/itrus/util/Semaphore:lock	()V
    //   7: aload_0
    //   8: aload_1
    //   9: putfield 52	com/itrus/cvm/CRLContext:m_X509CRL	Lcom/itrus/cert/X509CRL;
    //   12: aload_0
    //   13: iconst_0
    //   14: putfield 75	com/itrus/cvm/CRLContext:m_status	I
    //   17: aload_0
    //   18: getfield 73	com/itrus/cvm/CRLContext:m_semaphore	Lcom/itrus/util/Semaphore;
    //   21: invokevirtual 255	com/itrus/util/Semaphore:unlock	()V
    //   24: return
    //   25: astore_3
    //   26: aload_0
    //   27: getfield 73	com/itrus/cvm/CRLContext:m_semaphore	Lcom/itrus/util/Semaphore;
    //   30: invokevirtual 255	com/itrus/util/Semaphore:unlock	()V
    //   33: return
    //   34: astore_2
    //   35: aload_0
    //   36: getfield 73	com/itrus/cvm/CRLContext:m_semaphore	Lcom/itrus/util/Semaphore;
    //   39: invokevirtual 255	com/itrus/util/Semaphore:unlock	()V
    //   42: aload_2
    //   43: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   0	17	25	java/lang/InterruptedException
    //   0	17	34	finally
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cvm.CRLContext
 * JD-Core Version:    0.6.2
 */